var _util=require('../util/util.js')

var _order_service={
    //获取已登录用户的Orders
    getOrderList: function(resolve,reject){
        _util.request({
            url:_util.getServerURL('order/orders/myOrders'),
            method: 'GET',
            success:resolve,
            error:reject
        })
    },
    //生成订单
    newOrder: function(order, resolve, reject){
        _util.request({
            url:_util.getServerURL('order/orders/newOrder'),
            method: 'POST',
            data: order,
            success:resolve,
            error: reject
        })
    },
    getOrderById: function(orderId, resolve, reject){
        _util.request({
            url: _util.getServerURL(`order/orders/${orderId}`),
            method: 'GET',
            success: resolve,
            error: reject
        })
    },
    getItemByOrderId: function(orderId, resolve, reject){
        _util.request({
            url: _util.getServerURL(`order/orders/${orderId}/items`),
            method: 'GET',
            success: resolve,
            error: reject
        })
    },
    payOrder: function(order, resolve, reject){
        _util.request({
            url: _util.getServerURL("pay"),
            method: 'POST',
            data: order,
            success: resolve,
            error: reject
        })
    }
}

module.exports=_order_service;